const fs = require('node:fs');
const zlib = require('node:zlib');
// 压缩
const readStream = fs.createReadStream('./index.txt');
const writeStream = fs.createWriteStream('index.txt.gz');
readStream.pipe(zlib.createGzip()).pipe(writeStream);

// 解压
// const readStream2 = fs.createReadStream('index.txt.gz');
// const writeStream2 = fs.createWriteStream('index2.txt');
// readStream2.pipe(zlib.createGunzip()).pipe(writeStream2);

// 无损压缩
// const readStream3 = fs.createReadStream('./index.txt');
// const writeStream3 = fs.createWriteStream('index.txt.deflate');
// readStream3.pipe(zlib.createDeflate()).pipe(writeStream3);

//无损解压
// const readStream4 = fs.createReadStream('index.txt.deflate');
// const writeStream4 = fs.createWriteStream('index2.txt');
// readStream4.pipe(zlib.createInflate()).pipe(writeStream4);